<?php
header('Content-type: text/html; charset=utf-8');
$action = empty($_REQUEST['action']) ? 'index' : trim($_REQUEST['action']);
$template_name = "system/system_{$action}.htm";
$tpl->tpl_file = $template_name;
require_once "common.php";
error_reporting(E_NONE);
if($action=="key"){
        // START 检查权限
        if (!$perm->check_permission(SYSTEM,SYSTEM_SYS_KEY_CLASS)) {
                display_nopermission();
        } 
        // END 检查权限
        
		require_once "tools/tree/sort.class.php";
		//$DB->query("set names utf8");
		$tree = new SortClass($DB,'`t_reported_sys`');
		$category = $tree->getChilds();
        //$DB->query("set names latin1");
		function back(){
			echo '<script language="javascript">window.location.href="test.php?"+new Date().getTime();</script>';
			exit;
		}
		//生成select
		function makeSelect($array,$formName){
			global $tree;
			$select = '<select name="'.$formName.'" id="'.$formName.'">';
			foreach ($array as $id){
				$select.='<option value="'.$id.'">'.$tree->getLayer($id, '|-').$tree->getValue($id)."</option>";
			}
			return $select.'</select>';
		}
		function treelist($category){
			global $tree;
			foreach ($category as $id){
				$treelist.= '<li>'.$tree->getLayer($id, '|－ ').$tree->getValue($id).'(<strong>KEY:'.$tree->getKey($id).'</strong>) <a href="javascript:query_del(\'del\',\''.$tree->getKey($id).'\','.$id.')">Del</a> <a href="javascript:void(0)" onclick="mod
				('.$id.','.$tree->getParent($id).',\''.$tree->getValue($id).'\',\''.$tree->getRemark($id).'\')">Edit</a> </li>';
			}
			return $treelist;
		}
		$addSelect=makeSelect($category,'pid');
		$fromSelect=makeSelect($category,'who');
		$toSelect=makeSelect($category,'to');
		$treelist=treelist($category);
		$tpl->append("addSelect",$addSelect);
		$tpl->append("fromSelect",$fromSelect);
		$tpl->append("toSelect",$toSelect);
		$tpl->append("treelist",$treelist);
}

$tpl->output();



